/**
 * 
 */
package com.shengruan.user.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.shengruan.user.vo.AutoAuction;

/**
 * @author liubin
 *
 */
public class AutoAuctionUtil {

	public static Map<String,AutoAuction> autoAuctionMap = new HashMap<String,AutoAuction>();
	/***
	 * 新增
	 */
	public static void add(String id,AutoAuction autoAuction)
	{
		autoAuctionMap.put(id, autoAuction);
	}

	/**
	 * 删除
	 */
	public static void remove(String id)
	{
		autoAuctionMap.remove(id);
	}

	/**
	 * 根据ID获得
	 */
	public static AutoAuction get(String id)
	{
		return autoAuctionMap.get(id);
	}
	
	/***
	 * 根据商品ID删除
	 */
	public static void removeByProductId(int productId)
	{
		Set<String> keySet = autoAuctionMap.keySet();
		Iterator<String> iterator = keySet.iterator();
		List<String> idList = new ArrayList<String>();
		while(iterator.hasNext())
		{
			String idKey = iterator.next();
			if(idKey.endsWith("||"+productId))
			{
				idList.add(idKey);
			}
		}
		for(int i=0;i<idList.size();i++)
		{
			autoAuctionMap.remove(idList.get(i));
		}
	}
}
